package ace.cmp.data.spring.data.jdbc.querydsl.rsql.autoconfig;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.DtoManagerFactory;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.ManagerFactory;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.impl.DtoManagerFactoryImpl;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.impl.ManagerFactoryImpl;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.DtoManagerSpringFactory;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.ManagerSpringFactory;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.impl.DtoManagerSpringFactoryImpl;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.impl.ManagerSpringFactoryImpl;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.utils.SaveContextUtils;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslRelationHelper;
import ace.cmp.spring.util.core.SpringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/9/14 10:15
 */
@Configuration
public class QuerydslRsqlDataAutoConfig {


  @ConditionalOnMissingBean
  @Bean
  public DtoManagerFactory querydslRsqlManagerFactory(SpringUtils springUtils) {
    return new DtoManagerFactoryImpl(springUtils);
  }

  @ConditionalOnMissingBean
  @Bean
  public DtoManagerSpringFactory querydslRsqlManagerSpringFactory(
      SpringUtils springUtils, DtoManagerFactory dtoManagerFactory) {
    return new DtoManagerSpringFactoryImpl(dtoManagerFactory, springUtils);
  }

  @ConditionalOnMissingBean
  @Bean
  public ManagerFactory entityQuerydslRsqlManagerFactory(
      SpringUtils springUtils) {
    return new ManagerFactoryImpl(springUtils);
  }

  @ConditionalOnMissingBean
  @Bean
  public ManagerSpringFactory entityQuerydslRsqlManagerSpringFactory(
      SpringUtils springUtils, ManagerFactory managerFactory) {
    return new ManagerSpringFactoryImpl(
        managerFactory, springUtils);
  }
}
